package ai.plantdata.Behavior.mode.IteratorPattern.interfaces.impl;

import ai.plantdata.Behavior.mode.IteratorPattern.interfaces.Container;
import ai.plantdata.Behavior.mode.IteratorPattern.interfaces.Iterator;


/**
 * @Author: WangHui
 * @Date: 2020/12/23 14:14
 * @Description:
 */
public class NameRepository implements Container {
    public String[] names = {"Robert","John","Julie","Lora"};

    @Override
    public Iterator getInterator() {
        return new NameIterator();
    }

    private class NameIterator implements Iterator{

        int index;

        @Override
        public boolean hasNext() {
            if(index < names.length){
                return true;
            }
            return false;
        }

        @Override
        public Object nest() {
            if(this.hasNext()){
                return names[index++];
            }
            return null;
        }
    }
}
